package com.tranq;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


public class TrafficStatsApp
{
    public static void main( String[] args )
    {
        Configuration conf = new Configuration();
        try {
            Job job = Job.getInstance(conf, "TrafficStatApp");
            job.setJarByClass(TrafficStatsApp.class);
            job.setMapperClass(TrafficStatMapper.class);
            job.setCombinerClass(TrafficStatReducer.class);
            job.setReducerClass(TrafficStatReducer.class);
            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(TrafficStatRecord.class);
            FileInputFormat.addInputPath(job, new Path(args[0]));
            FileOutputFormat.setOutputPath(job, new Path(args[1]));
            System.exit(job.waitForCompletion(true) ? 0 : 1);

        } catch (IOException | InterruptedException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
